exports.addItemId = params => {
  const newPageList = [];
  if (params) {
    params.forEach((item, index) => {
      newPageList.push(item);
      newPageList[index].id = index;
      newPageList[index].error = false;
    });
  }
  return newPageList;
};

exports.connetBatch = (dataList, addList) => {
  let newPageList = [];
  const addPageList = [];
  dataList.forEach((item, index) => {
    newPageList.push(item);
  });
  if (newPageList.length !== 0 && !newPageList[0].sn) {
    newPageList.splice(0, 1);
  }
  addList.forEach((item, index) => {
    let flag = true;
    for (let i = 0; i < newPageList.length; i++) {
      if (item.sn === newPageList[i].sn) {
        flag = false;
        break;
      }
    }
    if (flag) {
      addPageList.push(item);
    }
  });
  newPageList = addPageList.concat(newPageList);
  newPageList.forEach((item, index) => {
    if (index < addPageList.length) {
      newPageList[index].id = dataList.length + index;
      newPageList[index].error = false;
    }
  });
  return newPageList;
};

exports.addOne = (dataList) => {
  const newPageList = [];
  const listLength = dataList.length;
  dataList.forEach((item, index) => {
    newPageList.push(item);
  });
  newPageList.unshift({ remark: '', sn: '', id: listLength, error: false });
  return newPageList;
};
